package Simulation;

import fxana.FxRawDataSet;
import fxana.RawDataCell;

public class ConditionLSMDouble extends ConditionLSM {
	static public Integer default_ref_numberofday=12; 
	/* This construct is for seed */
	public ConditionLSMDouble(){
		super();
	}
	public ConditionLSMDouble(FxRawDataSet ds, RawDataCell today,
			EvaluatorParaFlag flag) {
		super(ds, today, flag);
	}

	@Override
	protected Condition GetNew(FxRawDataSet ds, RawDataCell today,
			EvaluatorParaFlag flag) {
		return new ConditionLSMDouble(ds,today,flag);
	}

	@Override
	protected RawDataCell GetEstimatedValue(FxRawDataSet ds, RawDataCell today,
			EvaluatorParaFlag flag) {
		Integer numberofday=25;
		Integer ref_numberofday=ConditionLSMDouble.default_ref_numberofday;
		
		if(flag.IsMFlagSet()&&flag.GetMFlagIterator().hasNext()){
			numberofday=flag.GetMFlagIterator().next();
		}
		
		if(flag.IsRFlagSet()&&flag.GetRFlagIterator().hasNext()){
			ref_numberofday=flag.GetRFlagIterator().next();
		}
		
		RawDataCell est=ds.GetLSMDataByDate(today.GetRecDate(), numberofday);
		RawDataCell est_ref=ds.GetLSMDataByDate(today.GetRecDate(), ref_numberofday);
		if(est==null){
			return null;
		}
		
		if(est_ref==null){
			return est;
		}
		
		return new RawDataCell(today.GetFSRecDate(),
								 (est.GetStartValue()+est_ref.GetStartValue())/2,
								 (est.GetHighValue()+est_ref.GetHighValue())/2,
								 (est.GetLowValue()+est_ref.GetLowValue())/2,
								 (est.GetEndValue()+est_ref.GetEndValue())/2);
	}
	
}
